package com.example.ui_demo_widget;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;

import com.example.ui_demo_widget.adapter.MyRecyclerViewAdapter;

import java.util.ArrayList;

public class RecyclerViewActivity extends AppCompatActivity {
    private ArrayList<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);

        initData();
        RecyclerView rvDemo = findViewById(R.id.rv_demo);
//        线性布局
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//        layoutManager.setOrientation(RecyclerView.HORIZONTAL);
//        网格布局
//        GridLayoutManager layoutManager = new GridLayoutManager(this, 4);
//        layoutManager.setOrientation(RecyclerView.HORIZONTAL);
//        瀑布网格布局
        StaggeredGridLayoutManager staggeredGridLayoutManager =
                new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
        staggeredGridLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
        rvDemo.setLayoutManager(staggeredGridLayoutManager);

        rvDemo.setAdapter(new MyRecyclerViewAdapter(this, data));

    }

    private void initData() {
        data = new ArrayList<String>();
        for (int i = 'A'; i <= 'z'; i++) {
            data.add("" + (char) i);
        }
    }
}